cmake_minimum_required(VERSION 3.4.1)
# environment configuration
# set(CMAKE_CXX_COMPILER "/usr/bin/arm-linux-gnueabihf-g++")
# set(CMAKE_C_COMPILER "/usr/bin/arm-linux-gnueabihf-gcc")
set(CMAKE_CXX_COMPILER "/usr/bin/aarch64-linux-gnu-g++")
set(CMAKE_C_COMPILER "/usr/bin/aarch64-linux-gnu-gcc")
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I/usr/include/eigen3 -pthread -lrt -O3")
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I/usr/include/eigen3 -pthread -lrt -O3   -lLuMoSDK_C -lprotobuf -lzmq")

# 设置C++标准
set(CMAKE_CXX_STANDARD 14)

set(RPLT_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" CACHE FILEPATH "RPilot source directory" FORCE)
set(RPLT_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}" CACHE FILEPATH "RPilot binary directory" FORCE)

# project configuration
project(RflyPilot)
set(CMAKE_BUILD_TYPE "Release")

add_subdirectory(src/mavlink)

add_executable(RflyPilot
    main.c
    CThreadPool.c
)

message(STATUS "Link directories: ${CMAKE_LINK_DIRECTORIES}")
message(PATH_LIST "cmake output directory: ${RPLT_BINARY_DIR}")


# add_custom_target(
#     upload
#     COMMAND ../tools/upload.sh
# )

# upload configuration
set(REMOTE_USER "pi" CACHE STRING "Remote username")
set(REMOTE_HOST "192.168.0.111" CACHE STRING "Remote host address")

message(REMOTE_USER ":${REMOTE_USER}")
message(REMOTE_HOST ":${REMOTE_HOST}")

add_custom_target(
    upload
    COMMAND rsync -arh --progress
                    ${RPLT_BINARY_DIR}/RflyPilot
                    ${REMOTE_USER}@${REMOTE_HOST}:/home/${REMOTE_USER}/RflyPilot/
)

add_custom_target(
    userdir
    COMMAND ssh ${REMOTE_USER}@${REMOTE_HOST} 'mkdir -p ~/RflyPilot/'
    COMMENT "Creating remote directory RflyPilot/ on target machine"
)